package cc.lj.internal.coupons.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.core.model.BasePageHelper2;
import cc.lj.internal.core.model.PageBean;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.domain.martcap.repository.IMartCapRepository;
import cc.lj.internal.coupons.infrastructure.dao.IMartCapMapper;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.infrastructure.po.MartCapPO;
import cc.lj.internal.coupons.interfaces.dto.query.MartCapListQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("mysqlMartCapRepository")
public class MysqlMartCapRepositoryImpl implements IMartCapRepository,BasePageHelper<MartCapPO> {

    @Autowired
    private IMartCapMapper martCapMapper;

    @Override
    public Integer insert(MartCapPO martCapPO) {
        int row = martCapMapper.insert(martCapPO);
        if(row!=1)
        {
            throw new ServiceException(CoupousExceptionEnum.MART_CAP_MYSQL_INSERT);
        }
        return martCapPO.getId();
    }

    @Override
    public MartCapPO getById(Integer id) {
        MartCapPO martCapPO = martCapMapper.selectById(id);
        if(martCapPO==null)
        {
            throw new ServiceException(CoupousExceptionEnum.MART_CAP_MYSQL_SELECT);
        }
        return martCapPO;
    }

    @Override
    public Integer updateById(MartCapPO martCapPO) {
        return martCapMapper.updateById(martCapPO);
    }


    @Override
    public PageInfo<MartCapPO> selectPage(PageParam<MartCapPO> pageParam) {
        return this.page(pageParam);
    }

    /**
     * PageHelper接口方法
     * @param param 查询参数
     * @return
     */
    @Override
    public List<MartCapPO> list(MartCapPO param) {
        QueryWrapper wrapper = new QueryWrapper(param);
        List<MartCapPO> list = martCapMapper.selectList(wrapper);
        return list;
    }

    /**
     * 通过主键id in 查询
     * @param idList
     * @return
     */
    @Override
    public List<MartCapPO> getByIdIn(List idList) {
        return martCapMapper.selectBatchIds(idList);
    }
}
